package com.lm.langchain4j.controller;

import com.lm.langchain4j.service.DocumentService;
import com.lm.langchain4j.service.QAService;
import org.springframework.web.bind.annotation.*;

import java.nio.file.Path;

@RestController
@RequestMapping("/api/qa")
public class QAController {

    private final DocumentService documentService;
    private final QAService qaService;

    public QAController(DocumentService documentService, QAService qaService) {
        this.documentService = documentService;
        this.qaService = qaService;
    }

    @PostMapping("/load")
    public String load(@RequestParam String path) throws Exception {
        documentService.loadAndIndex(Path.of(path), 1000, 200);
        return "ok";
    }

    @GetMapping("/ask")
    public String ask(@RequestParam String q, @RequestParam(defaultValue = "3") int k) {
        return qaService.ask(q, k);
    }
}

